import vueRouter from "vue-router"
import Vue from "vue"
// console.log(vueRouter);

import Home from "./components/Home.vue"
import Category from "./components/Category.vue"
import Cart from "./components/Cart.vue"
import MyView from "./components/MyView.vue"
import Login from "./components/Login.vue"
import Detail from "./components/Detail.vue"
import Order from "./components/OrderView.vue"
import Next from "./components/nextTick.vue"

// 把路由的组件挂在vue的内置组件当中
Vue.use(vueRouter)

const routes = [
    {
        // path 路径  component 页面
        path: "/",
        redirect: "/home"
    }, {
        path: "/home",
        component: Home,
        meta: {
            title: '首页',
            keepAlive: true
        }
    }
    , {
        path: "/category",
        component: Category,
        meta: {
            title: '分类',
            keepAlive: false
        }
    }
    , {
        path: "/cart",
        component: Cart,
        meta: {
            title: '购物车',
            keepAlive: false
        }
    },
    {
        path: "/my",
        component: MyView,
        meta: {
            title: '我的',
            keepAlive: false
        }
    },
    {
        path: "/login",
        component: Login,
    },
    {
        path: "/detail",
        component: Detail,
    },
    {
        path: "/order",
        component: Order,
    },
    {
        path: "/next",
        component: Next,
    }
]

// vue路由的实例化
const router = new vueRouter({
    routes
})

/* router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    console.log(to, from, next)
    next()
}) */

// 导出路由模块
export default router